package pers.linkong.asr.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import pers.linkong.asr.domain.SchedulerBean;
import pers.linkong.asr.service.SchedulerService;
import pers.linkong.asr.util.LayPage;
import pers.linkong.asr.util.ResultInfo;

@Controller
@RequestMapping("/time")
public class ScheduleController {

	@Autowired
	private SchedulerService schedulerService;
	
	@RequestMapping("/getSchedulerByLesson")
	@ResponseBody
	public SchedulerBean getSchedulerByLesson(int lesson, HttpSession session) throws Exception {
		SchedulerBean bean = this.schedulerService.getSchedulerByLesson(lesson);
		return bean;
	}
	
	@RequestMapping("/getScheduler")
	@ResponseBody
	public LayPage getScheduler(HttpSession session) throws Exception {
		List<SchedulerBean> list = this.schedulerService.getScheduler();
		return LayPage.data(1, "", (long) 0, list);
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public ResultInfo updateScheduler(SchedulerBean schedulerBean, HttpSession session) {
		System.out.println("准备修改:" + schedulerBean.getLesson());
		try {
			this.schedulerService.updateScheduler(schedulerBean);
			return ResultInfo.data(1, "保存成功");
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return ResultInfo.data(0, "发生异常，保存失败，请稍后再试");
		}
	}
}
